#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "uthash.h"

#include <iso646.h>

/**
 * Definition for singly-linked list.
 */
struct ListNode {
	int val;
	struct ListNode* next;
};
typedef struct ListNode list_node, *list_node_ptr;

struct ListNode* partition(struct ListNode* head, int x);

int main()
{
	return 0;
}

struct ListNode* partition(struct ListNode* head, int x)
{
	list_node aux_head = { 0, head }, aux = { 0, NULL };

	list_node_ptr p = &aux_head, p_aux = &aux;
	for (list_node_ptr next = p->next; next; p = p->next, next = p->next) {
		printf("{%d,%p}\n", p->val, p->next);
		while ((next = p->next) && next->val >= x) {
			/* 主链中剔除 */
			p->next = next->next;
			/* 挂到辅助链表上 */
			next->next = p_aux->next;
			p_aux->next = next;
			p_aux = next;
		}
	}
	p->next = aux.next;

	return aux_head.next;
}
